//
//  TabbarViewController.m
//  Crocodile
//
//  Created by tin vu on 8/29/12.
//  Copyright (c) 2012 hust. All rights reserved.
//

#import "TabbarViewController.h"
#import "Constant.h"
#import "SplashScreenView.h"

@interface TabbarViewController ()

@end

@implementation TabbarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    SplashScreenView *splashScreenView = [[SplashScreenView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    splashScreenView.mViewCtrl = self;
    self.view = splashScreenView;
    [splashScreenView release];
    
	// Do any additional setup after loading the view.
    UIColor *backgroundColor = [UIColor whiteColor];
    self.view.backgroundColor = backgroundColor;
    self.navigationController.navigationBarHidden = YES;
    
    _tabbarController = [[UITabBarController alloc] init];
    NSMutableArray *controllers = [[NSMutableArray alloc] init];
    
    // Set tabbar view items
    _homeViewController = [[HomeViewController alloc] init];
    [_homeViewController setTitle:kStrHomeTabTitle];
    _homeViewController.tabBarItem.image = [UIImage imageNamed:kImgHomeTab];
    _homeNavigationController = [[UINavigationController alloc] initWithRootViewController:_homeViewController];
    _homeNavigationController.navigationBarHidden = YES;
    [controllers addObject:_homeNavigationController];
    
    
    _musicViewController = [[MusicViewController alloc] init];
    [_musicViewController setTitle:kStrMusicTabTitle];
    _musicViewController.tabBarItem.image = [UIImage imageNamed:kImgMusicTab];
    //_musicViewController.hidesBottomBarWhenPushed = YES;
    _musicNavigationController = [[UINavigationController alloc] initWithRootViewController:_musicViewController];
    _musicNavigationController.navigationBarHidden = NO;
    [controllers addObject:_musicNavigationController];
    
    _newsViewController = [[NewsViewController alloc] init];
    [_newsViewController setTitle:kStrNewsTabTitle];
    _newsViewController.tabBarItem.image = [UIImage imageNamed:kImgNewsTab];
    _newsNavigationController = [[UINavigationController alloc] initWithRootViewController:_newsViewController];
    _newsNavigationController.navigationBarHidden = YES;
    [controllers addObject:_newsNavigationController];
    
    _showsViewController = [[ShowsViewController alloc]init];
    [_showsViewController setTitle:kStrShowTabTitle];
    _showsViewController.tabBarItem.image = [UIImage imageNamed:kImgShowsTab];
    _showsNavigationController = [[UINavigationController alloc]initWithRootViewController:_showsViewController];
    _showsNavigationController.navigationBarHidden = YES;
    [controllers addObject:_showsNavigationController];

    
    _aboutViewController = [[AboutViewController alloc] init];
    [_aboutViewController setTitle:kStrAboutTabTitle];
    _aboutViewController.tabBarItem.image = [UIImage imageNamed:kImgAboutTab];
    _aboutNavigationController = [[UINavigationController alloc] initWithRootViewController:_aboutViewController];
    _aboutNavigationController.navigationBarHidden = YES;
    [controllers addObject:_aboutNavigationController];
    
    // Set tabbar
    _tabbarController.viewControllers = controllers;
    _tabbarController.customizableViewControllers = controllers;
    [_tabbarController setSelectedViewController:_homeNavigationController];
    [controllers release];
    _tabbarController.delegate = self;
    _tabbarController.view.frame = CGRectMake(0, 0, 320, 460);
   // [self.view addSubview:_tabbarController.view];
    
    [self performSelector:@selector(pushToHomeView) withObject:nil afterDelay: 2];

}

-(void)pushToHomeView
{
    [self.navigationController pushViewController:_tabbarController animated:YES];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    [_tabbarController release];
    [_homeViewController release];
    [_newsViewController release];
    [_musicViewController release];
    [_aboutViewController release];
    [_homeNavigationController release];
    [_newsNavigationController release];
    [_musicNavigationController release];
    [_aboutNavigationController release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
